package com.ruoyi.web.controller.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.web.controller.demo.domain.SysWzxUser;
import com.ruoyi.web.controller.mapper.SysSchedulPaiRelateMapper;
import com.ruoyi.web.controller.demo.domain.SysSchedulPaiRelate;
import com.ruoyi.web.controller.service.ISysSchedulPaiRelateService;
import com.ruoyi.common.core.text.Convert;

/**
 * schedul_pai_relateService业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-27
 */
@Service
public class SysSchedulPaiRelateServiceImpl implements ISysSchedulPaiRelateService 
{
    @Autowired
    private SysSchedulPaiRelateMapper sysSchedulPaiRelateMapper;

    /**
     * 查询schedul_pai_relate
     * 
     * @param id schedul_pai_relate主键
     * @return schedul_pai_relate
     */
    @Override
    public List<SysSchedulPaiRelate> selectSysSchedulPaiRelateById(Long id)
    {
        return sysSchedulPaiRelateMapper.selectSysSchedulPaiRelateById(id);
    }

    /**
     * 查询schedul_pai_relate列表
     * 
     * @param sysSchedulPaiRelate schedul_pai_relate
     * @return schedul_pai_relate
     */
    @Override
    public List<SysSchedulPaiRelate> selectSysSchedulPaiRelateList(SysSchedulPaiRelate sysSchedulPaiRelate)
    {
        return sysSchedulPaiRelateMapper.selectSysSchedulPaiRelateList(sysSchedulPaiRelate);
    }

    /**
     * 新增schedul_pai_relate
     * 
     * @param sysSchedulPaiRelate schedul_pai_relate
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSysSchedulPaiRelate(SysSchedulPaiRelate sysSchedulPaiRelate)
    {
        int rows = sysSchedulPaiRelateMapper.insertSysSchedulPaiRelate(sysSchedulPaiRelate);
        insertSysWzxUser(sysSchedulPaiRelate);
        return rows;
    }

    /**
     * 修改schedul_pai_relate
     * 
     * @param sysSchedulPaiRelate schedul_pai_relate
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSysSchedulPaiRelate(SysSchedulPaiRelate sysSchedulPaiRelate)
    {
        sysSchedulPaiRelateMapper.deleteSysWzxUserByUserId(sysSchedulPaiRelate.getId());
        insertSysWzxUser(sysSchedulPaiRelate);
        return sysSchedulPaiRelateMapper.updateSysSchedulPaiRelate(sysSchedulPaiRelate);
    }

    /**
     * 批量删除schedul_pai_relate
     * 
     * @param ids 需要删除的schedul_pai_relate主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysSchedulPaiRelateByIds(String ids)
    {
        sysSchedulPaiRelateMapper.deleteSysWzxUserByUserIds(Convert.toStrArray(ids));
        return sysSchedulPaiRelateMapper.deleteSysSchedulPaiRelateByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除schedul_pai_relate信息
     * 
     * @param id schedul_pai_relate主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysSchedulPaiRelateById(Long id)
    {
        sysSchedulPaiRelateMapper.deleteSysWzxUserByUserId(id);
        return sysSchedulPaiRelateMapper.deleteSysSchedulPaiRelateById(id);
    }

    /**
     * 新增人员信息信息
     * 
     * @param sysSchedulPaiRelate schedul_pai_relate对象
     */
    public void insertSysWzxUser(SysSchedulPaiRelate sysSchedulPaiRelate)
    {
        List<SysWzxUser> sysWzxUserList = sysSchedulPaiRelate.getSysWzxUserList();
        Long id = sysSchedulPaiRelate.getId();
        if (StringUtils.isNotNull(sysWzxUserList))
        {
            List<SysWzxUser> list = new ArrayList<SysWzxUser>();
            for (SysWzxUser sysWzxUser : sysWzxUserList)
            {
                sysWzxUser.setUserId(id);
                list.add(sysWzxUser);
            }
            if (list.size() > 0)
            {
                sysSchedulPaiRelateMapper.batchSysWzxUser(list);
            }
        }
    }
}
